import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import 'sample_bloc.dart';

class FlutterBlocDemo2Home extends StatefulWidget {
  const FlutterBlocDemo2Home({Key? key}) : super(key: key);

  @override
  _FlutterBlocDemo2HomeState createState() => _FlutterBlocDemo2HomeState();
}

class _FlutterBlocDemo2HomeState extends State<FlutterBlocDemo2Home> {
  CounterBloc _bloc = CounterBloc();

  @override
  void dispose() {
    super.dispose();
    _bloc.close();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: BlocBuilder<CounterBloc, CounterState>(
        cubit: _bloc,
        builder: (context, state) {
          return Center(
            child: Text(
              "${state.count}",
              style: TextStyle(fontSize: 28),
            ),
          );
        },
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          _bloc.increment();
        },
        child: Icon(Icons.add),
      ),
    );
  }
}
